package com.spark.lola.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.spark.lola.entity.warehouse.StoreProduct;
import com.spark.lola.mapper.StoreProductMapper;
import com.spark.lola.service.IStoreProductService;
import com.spark.lola.support.mybatis.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author dengyejun
 * @since 2020-06-10
 */
@Service
public class StoreProductServiceImpl extends BaseServiceImpl<StoreProductMapper, StoreProduct> implements IStoreProductService {

    @Override
    public List<StoreProduct> getListByStoreId(Long storeId) {
        QueryWrapper<StoreProduct> query = new QueryWrapper<>();
        query.eq("store_id", storeId);
        List<StoreProduct> lst = baseMapper.selectList(query);
        if (CollectionUtils.isEmpty(lst)) {
            lst = new ArrayList<>();
        }
        return lst;
    }

    @Override
    public List<StoreProduct> getListByProductId(Long productId) {
        QueryWrapper<StoreProduct> query = new QueryWrapper<>();
        query.eq("product_id", productId);
        List<StoreProduct> lst = baseMapper.selectList(query);
        if (CollectionUtils.isEmpty(lst)) {
            lst = new ArrayList<>();
        }
        return lst;    }
}
